package 寒假刷题;

public class 二进制表示中质数个计算置位 {
    public int countPrimeSetBits(int left, int right) {
        int count = 0;
        for (int i = left; i <= right; i++) {
            boolean prime = isPrime(Integer.bitCount(i));
            if (prime)
                count++;
        }
        return count;
    }
    //判断一个数是否为质数
    public boolean isPrime(int num){
        if (num<2)
            return false;
        for (int i = 2; i*i <= num; i++) {
            if (num%i==0)
                return false;
        }
        return true;
    }
}
